/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package com.spring_shiro.common;

import org.apache.shiro.authz.AuthorizationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.NoHandlerFoundException;
import org.yaml.snakeyaml.constructor.DuplicateKeyException;

/**
 * 异常处理器
 *
 * @author Mark sunlightcs@gmail.com
 */
@RestControllerAdvice
public class RRExceptionHandler {
	private Logger logger = LoggerFactory.getLogger(getClass());

	@ExceptionHandler(NoHandlerFoundException.class)
	public String handlerNoFoundException(Exception e) {
		logger.error(e.getMessage(), e);
		return "路径不存在，请检查路径是否正确";
	}

	@ExceptionHandler(DuplicateKeyException.class)
	public String handleDuplicateKeyException(DuplicateKeyException e){
		logger.error(e.getMessage(), e);
		return "数据库中已存在该记录";
	}

	@ExceptionHandler(AuthorizationException.class)
	public String handleAuthorizationException(AuthorizationException e){
		logger.error(e.getMessage(), e);
		return "没有权限，请联系管理员授权";
	}

	@ExceptionHandler(Exception.class)
	public String handleException(Exception e){
		logger.error(e.getMessage(), e);
		return "wuwuwuuw";
	}
}
